<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page contentType="text/xml"%>
<%@page pageEncoding="UTF-8"%>
<%
        response.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
        response.setHeader("Pragma", "no-cache"); //HTTP 1.0
        response.setDateHeader("Expires", 0); //prevent caching at the proxy server
%>
<sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
    select a.id_alocacao,
    a.id_turma,
    a.data_alocacao,
    hora_inicio,
    hora_fim ,
    c.nome_curso,
    o.desc_componente,
    d.matricula ,
    d.nome as docente,
    s.desc_sala,
    a.situacao,
    a.otimizado
    from Alocacoes a
    inner join Turmas  t on a.id_turma=t.id_turma
    inner join turnos h on t.id_turno=h.id_turno
    inner join Cursos c on c.id_curso=t.id_curso
    inner join Componentes o on o.id_componente=a.id_componente
    left join Docentes d on d.matricula=a.matricula
    inner join salas s on a.id_sala=s.id_sala
    where a.id_turma=? and a.id_componente=?
    <sql:param value="${param.id_turma}"/>
    <sql:param value="${param.id_componente}"/>
    order by id_alocacao
</sql:query>

<rows>
    <c:choose>
        <c:when test="${empty param.page}">
            <page>1</page>
        </c:when>
        <c:otherwise>
            <page>${param.page}</page>
        </c:otherwise>
    </c:choose>
    <total><fmt:formatNumber value="${query.rowCount/10}" pattern="######"/></total>
    <records>${query.rowCount} </records>
    <c:forEach var="row" items="${query.rows}">
        <row id ="${row.id_alocacao}">
            <cell><fmt:formatDate pattern="dd/MM/yyyy" value="${row.data_alocacao}"/></cell>
            <cell>${fn:trim(row.hora_inicio)}</cell>
            <cell>${fn:trim(row.hora_fim)}</cell>
            <cell>${fn:trim(row.desc_sala)}</cell>
            <cell>${row.docente}</cell>
            <cell><![CDATA[${fn:trim(row.situacao)}]]></cell>
            <cell><![CDATA[${fn:trim(row.otimizado)}]]></cell>
        </row>
    </c:forEach>
</rows>